package com.zbkj.admin.disruptor;

import cn.hutool.extra.spring.SpringUtil;
import com.lmax.disruptor.RingBuffer;
import com.zbkj.admin.listener.OrderCreateListener;

/**
 * 生产
 */
public class OrderEventProducer {
    private final RingBuffer<OrderEvent> ringBuffer;
    public OrderEventProducer(RingBuffer<OrderEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void onData(String orderId, String type) {
        onData(orderId, type, null);
    }
    public void onData(String orderId, String type, String orderStatus) {
        long sequence = ringBuffer.next();
        try {
            OrderEvent orderEvent = ringBuffer.get(sequence);
            orderEvent.setId(orderId);
            orderEvent.setType(type);
            orderEvent.setOrderStatus(orderStatus);
        } finally {
            ringBuffer.publish(sequence);
        }

    }
}